#include "Headers.h"

using namespace CinePerfil;
using namespace msclr::interop;

System::Void Series_To_Follow_Window::STFW_Done_Click(System::Object^  sender, System::EventArgs^  e)
{
	this->Owner->Show();
	this->Close();
}
System::Void Series_To_Follow_Window::STFW_addButton_Click(System::Object^  sender, System::EventArgs^  e)
{
	if(STFW_LB1->SelectedIndex != -1)
	{
		String^ selected = STFW_LB1->GetItemText(STFW_LB1->SelectedItem);

		account->add_serie(marshal_as<string>(selected));
		STFW_LB1->Items->RemoveAt(STFW_LB1->SelectedIndex);
		STFW_LB2->Items->Add(selected);
	}
}
System::Void Series_To_Follow_Window::STFW_removeButton_Click(System::Object^  sender, System::EventArgs^  e)
{
	if(STFW_LB2->SelectedIndex != -1)
	{
		String^ selected = STFW_LB2->GetItemText(STFW_LB2->SelectedItem);

		account->remove_serie(marshal_as<string>(selected));
		STFW_LB2->Items->RemoveAt(STFW_LB2->SelectedIndex);
		STFW_LB1->Items->Add(selected);
	}
}
System::Void Series_To_Follow_Window::load_info()
{
	String^ title;

	vector <string> account_series = account->get_series_to_follow();
	for (unsigned int i=0; i<account_series.size(); i++)
	{
		this->STFW_LB2->Items->Add(marshal_as<String^>(account_series[i]));
	}

	vector <Serie> database_series = database->get_series();
	for (unsigned int i=0; i<database_series.size(); i++)
	{
		title = marshal_as<String^>(database_series[i].get_title());
		if (!this->STFW_LB2->Items->Contains(title))
		{
			this->STFW_LB1->Items->Add(title);
		}
	}
}

